﻿using MLSMooc.BO;
using MLSMooc.DAO.Interface.Textbook;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using MLSMooc.Helper;
using Dapper;

namespace MLSMooc.DAO.Implement.Textbook
{
   public class TextbookDAO :ITextbookDAO
    {
        private static TextbookDAO instance = new TextbookDAO();
        private TextbookDAO() { }
        public static TextbookDAO Getinstance() => instance;

        public static readonly string queryField = "select * from Mooc_Course_Textbooks where isDelete=0 ";

        public async Task<IEnumerable<TextbookBO>> GetByIdTextbookInfo(string id)
        {
            using (SqlConnection conn=new SqlConnection(SalesSysSqlHelper.connectionString))
            {
                StringBuilder sql = new StringBuilder(queryField);
                sql.Append($@" and Id in("+id+")");
                var res = await conn.QueryAsync<TextbookBO>(sql.ToString());
                return res;
            }
        }


        public async Task<IEnumerable<TextbookBO>> GetTextbookAllList()
        {
            using (SqlConnection conn=new SqlConnection(SalesSysSqlHelper.connectionString))
            {
                StringBuilder sql = new StringBuilder(queryField);
                var res = await conn.QueryAsync<TextbookBO>(sql.ToString());
                return res;
            }
        }
    }
}
